package com.xinsoft.controller.basic;

import com.alibaba.fastjson.JSON;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysLevelPriceRefAddDTO;
import com.xinsoft.entity.dto.SysLevelPriceRefDTO;
import com.xinsoft.entity.dto.SysLevelPriceRefParam;
import com.xinsoft.service.SysLevelPriceRefService;
import com.xinsoft.validator.ValidatorUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 云供应链/销售管理/等级价格
 */
@Slf4j
@RestController
@RequestMapping("/system/levelPriceRef")
public class SysLevelPriceRefController {
    @Autowired
    private SysLevelPriceRefService levelPriceRefService;

    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody SysLevelPriceRefParam param) {
        return Response.succeed(levelPriceRefService.findPageListByParam(param));
    }

    /**
     * 所有客户等级
     */
    @GetMapping("/allLevel")
    public Response<?> allLevel() {
        return Response.succeed(levelPriceRefService.allLevel());
    }

    /**
     * 新增或修改
     */
    @PostMapping("/addOrUpdate")
    public Response<?> addOrUpdate(@RequestBody List<Map<String, Object>> mapList) {
        log.info("mapList：{}", JSON.toJSONString(mapList));
        levelPriceRefService.addOrUpdate(mapList);
        return Response.succeed();
    }

    /**
     * 批量改价
     */
    @PostMapping("/batchUpdatePrice")
    public Response<?> batchUpdatePrice(@RequestBody SysLevelPriceRefDTO sysLevelPriceRefDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(sysLevelPriceRefDTO);
        levelPriceRefService.batchUpdatePrice(sysLevelPriceRefDTO);
        return Response.succeed();
    }

}
